import dayjs from 'dayjs'

function isDate(value) {
    try {
        var date = new Date(value)
        return !isNaN(date.getTime())
    } catch(error) {
        console.error(error)
    }
}
export default {
    updated(el, binding, vnode) {
        const { value } = binding
        if (isDate(value)) {
            let curDate = dayjs(new Date())
            let targeDate = dayjs(value)
            const diffDay = targeDate.diff(curDate, 'day')
            let text = ''
            if (diffDay < 0) {
                text = "已逾期"
            } else if (diffDay === 0 ) {
                text = "今日"
            } else {
                text =  `${diffDay}天后`
            }
            el.innerText = text
        } else {
            el.innerText = ""
        }
    },
}